﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Windows;
using System.Drawing.Drawing2D;
using OCRGUI2008;
using System.Net.NetworkInformation;
using System.Net;
using System.Runtime.InteropServices;
using System.Security;






namespace OCRGUI2008
{


    unsafe public partial class frmOCR : Form
    {

//         [UIPermissionAttribute(SecurityAction.Demand, Clipboard = UIPermissionClipboard.OwnClipboard)]
//public void Paste();

        //Global Variable storing fullpath of image
         string FullPath = "";
        //Global Variable to store the method
         string  METHOD;

        //Global Variable to store from and to language
         string fromLang = "";
         string toLang = "";


        //Global variables start and end pixels
        int startX = 0;
        int startY = 0;
        int endX = 0;
        int endY = 0;

        //Old user resolution
        int RES1 = 0;
        int RES2 = 0;

        //Global Image, width and height variable
        Bitmap ImagePaint;
        int ImagePaint_width = 0;
        int ImagePaint_height = 0;

        //Global Variables storing the dimensions of the picture control box
        int pbbox_width = 0;
        int pbbox_height = 0;
        int pbboxX = 0;
        int pbboxY = 0;
        int pbboxX1 = 0;
        int pbboxY1 = 0;


        int _selectX = 0;
        int _selectY = 0;


        int eX = 0;

        //Global Variable used to determine if the selection tool should be turn on
        private bool _selecting;
        private Rectangle _selection;
        int trigger = 0;
     

        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
        public HttpWebResponse resp;

        
        private int FixHeight = 1280, FixWidth = 1024;
        private System.ComponentModel.Container components = null;
        
        public frmOCR()
        {
            InitializeComponent();
         
        }

        public static bool IsConnected()
        {
            int Description;
            return InternetGetConnectedState(out Description, 0);
        }

        public bool network_connection_test()
        {
            bool result = false;
            try
            {
                result = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();


            }
            catch
            {

                result = false; // host not reachable

            }
            return result;

        }

        private void Form1_Load(object sender, EventArgs e)
        {

            

            //  //Screen resolution
            //Rectangle r = Screen.GetBounds(this);

            //this.Location = new Point(0, 0);

            ////this.Size = r.Size;

            //double PercWidthChng = (r.Width - 1920);

            //PercWidthChng /= 1920;

            //double PercHeightChng = (r.Height - 1200);

            //PercHeightChng /= 1200;
            
               Screen Srn = Screen.PrimaryScreen;
               RES1 = Srn.Bounds.Width;
               RES2 = Srn.Bounds.Height;

            if (RES1 > 1920 && RES2 > 1200)
            { 
               

                this.WindowState = FormWindowState.Maximized;
                double widthPercent = Convert.ToDouble(RES1) / 1280;
                double heightPercent = Convert.ToDouble(RES2) / 1024;
                double oldformwidth = Convert.ToDouble(this.Width);
                double oldformheight = Convert.ToDouble(this.Height);
                this.Width = (Convert.ToInt32(Convert.ToDouble(this.Width) * widthPercent));
                this.Height = (Convert.ToInt32(Convert.ToDouble(this.Height) * heightPercent) + 110);
                double formWidthPercentage = Convert.ToDouble(this.Width) / oldformwidth;
                double formHeightPercentage = Convert.ToDouble(this.Height) / oldformheight;



                this.OCRPanel.Height = (Convert.ToInt32(Convert.ToDouble(OCRPanel.Height) * formHeightPercentage));
                this.OCRPanel.Width = (Convert.ToInt32(Convert.ToDouble(OCRPanel.Width) * formWidthPercentage));

                foreach (Control formcontrol in this.Controls)
                {
                    formcontrol.Width = Convert.ToInt32(Convert.ToDouble(formcontrol.Width) * formWidthPercentage);
                    formcontrol.Height = Convert.ToInt32(Convert.ToDouble(formcontrol.Height) * formHeightPercentage);
                    formcontrol.Location = new Point(Convert.ToInt32(Convert.ToDouble(formcontrol.Location.X) * formWidthPercentage), Convert.ToInt32(Convert.ToDouble(formcontrol.Location.Y * formHeightPercentage) + 10));
                    formcontrol.Font = new Font("Ariel", Convert.ToInt32(Convert.ToDouble(formcontrol.Font.Size) * .75), FontStyle.Regular);

                    this.toolStrip1.Height = Convert.ToInt32(this.toolsToolStripMenuItem.Height * formHeightPercentage);
                    // this.toolStrip1.Width = Convert.ToInt32(this.toolsToolStripMenuItem.Width * formWidthPercentage);


                }

                //Resolution.CResolution ChangeRes = new Resolution.CResolution(FixHeight, FixWidth);
            }
            else if (RES1 < 1280 || RES2 < 864)
            {
                Screen Srn1 = Screen.PrimaryScreen;
                RES1 = Srn1.Bounds.Width;
                RES2 = Srn1.Bounds.Height;

                double widthPercent = Convert.ToDouble(RES1) / 1280;
                double heightPercent = Convert.ToDouble(RES2) / 1024;
                double oldformwidth = Convert.ToDouble(this.Width);
                double oldformheight = Convert.ToDouble(this.Height);
                this.Width = (Convert.ToInt32(Convert.ToDouble(this.Width) * widthPercent));
                this.Height = (Convert.ToInt32(Convert.ToDouble(this.Height) * heightPercent) + 110);
                double formWidthPercentage = Convert.ToDouble(this.Width) / oldformwidth;
                double formHeightPercentage = Convert.ToDouble(this.Height) / oldformheight;



                this.OCRPanel.Height = (Convert.ToInt32(Convert.ToDouble(OCRPanel.Height) * formHeightPercentage));
                this.OCRPanel.Width = (Convert.ToInt32(Convert.ToDouble(OCRPanel.Width) * formWidthPercentage));
                this.WindowState = FormWindowState.Maximized;
                foreach (Control formcontrol in this.Controls)
                {
                    formcontrol.Width = Convert.ToInt32(Convert.ToDouble(formcontrol.Width) * formWidthPercentage);
                    formcontrol.Height = Convert.ToInt32(Convert.ToDouble(formcontrol.Height) * formHeightPercentage);
                    formcontrol.Location = new Point(Convert.ToInt32(Convert.ToDouble(formcontrol.Location.X) * formWidthPercentage), Convert.ToInt32(Convert.ToDouble(formcontrol.Location.Y * formHeightPercentage) + 10));
                    formcontrol.Font = new Font("Ariel", Convert.ToInt32(Convert.ToDouble(formcontrol.Font.Size) * .75), FontStyle.Regular);

                    this.toolStrip1.Height = Convert.ToInt32(this.toolsToolStripMenuItem.Height * formHeightPercentage);
                    // this.toolStrip1.Width = Convert.ToInt32(this.toolsToolStripMenuItem.Width * formWidthPercentage);
                }
            }
            else
            {
                this.WindowState = FormWindowState.Normal;
            }
           
 


            this.Refresh();


            //Adds the selctions to the method Cmb boxes
            cmbMethodFill(this.cmbMethod);
           cmbMethodFill(this.toolStripMethodComboBox);
           cmbMethodFill(this.toolStripMethodComboBoxButton);



            //Populates the Languiage combo boxes
            cmbLanguagesFill(this.toolStripFromComboBox);
            cmbLanguagesFill(this.toolStripToComboBox);
            cmbLanguagesFill(this.toolStripFromComboBoxButton);
            cmbLanguagesFill(this.toolStripToComboBoxButton);
            cmbLanguagesFill(this.cmbLanFrom);
            cmbLanguagesFill(this.cmbLanTo);

        }
        

    
 


        private void picOCRImage_MouseMove(object sender, MouseEventArgs e)
        {
            pbboxX = e.X;
            pbboxY = e.Y;
            _selectX = pbboxX - pbboxX1;
            _selectY = pbboxY - pbboxY1;

            // Update the actual size of the selection:
            if (_selecting)
            {







                if (_selectX < 0)
                {

                    _selection.X = pbboxX;





                }




                if (_selectY < 0)
                {
                    _selection.Y = pbboxY;

                }

                _selection.Width = Math.Abs(_selectX);

                _selection.Height = Math.Abs(_selectY);


                // Redraw the picturebox:
                picOCRImage.Refresh();


            }


        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            //_selection = e.Location;
            //Invalidate(); 

        }

       

        private void picOCRImage_Paint(object sender, PaintEventArgs e)
        {
           if (_selecting)
            {
                // Draw a rectangle displaying the current selection
                Pen pen = Pens.GreenYellow;
                e.Graphics.DrawRectangle(pen, _selection);

                //pen.Alignment = PenAlignment.Inset;







            }
        }

        private void picOCRImage_MouseDown(object sender, MouseEventArgs e)
        {

            pbboxX = e.X;
            pbboxY = e.Y;






            if (trigger == 0)
            {
                _selecting = true;
                _selection = new Rectangle(new Point(pbboxX, pbboxY), new Size());
                pbboxX1 = _selection.X;
                pbboxY1 = _selection.Y;

            }
            // Starting point of the selection:
            if (e.Button == MouseButtons.Left)
            {
                if (trigger == 0)
                {

                    trigger = trigger + 1;
                    PixelCalc newpixX = new PixelCalc(e.X, ImagePaint_width, pbbox_width);
                    PixelCalc newpixY = new PixelCalc(e.Y, ImagePaint_height, pbbox_height);

                    int newXVal = newpixX.CalculatePixels();
                    int newYVal = newpixY.CalculatePixels();


                    this.lblStartXY.Text = newpixX.CalculatePixels().ToString() + "," + newpixY.CalculatePixels().ToString();
                    this.lblStartX.Text = "X= " + newpixX.CalculatePixels().ToString();

                    this.lblStartY.Text = "Y= " + newpixY.CalculatePixels().ToString();
                    startX = newpixX.CalculatePixels();
                    startY = newpixY.CalculatePixels();

                }
                else
                {
                    _selecting = false;
                    trigger = 0;

                }

            }



        }



        private void picOCRImage_MouseUp(object sender, MouseEventArgs e)
        {
            int switchX = 0;
            int switchY = 0;

            _selecting = false;
            // Redraw the picturebox:
            PixelCalc newpixX = new PixelCalc(e.X, ImagePaint_width, pbbox_width);
            PixelCalc newpixY = new PixelCalc(e.Y, ImagePaint_height, pbbox_height);

            endX = newpixX.CalculatePixels();
            endY = newpixY.CalculatePixels();

            if (startX < endX)
            {
                this.lblEndPixelsXY.Text = endX.ToString() + ",";
                this.lblEndX.Text = "X= " + endX.ToString();
                this.lblStartXY.Text = startX.ToString() + ",";
                this.lblStartX.Text = "X= " + startX.ToString();

            }
            else
            {
                this.lblEndPixelsXY.Text = startX.ToString() + ",";
                this.lblEndX.Text = "X= " + startX.ToString();
                this.lblStartXY.Text = endX.ToString() + ",";
                this.lblStartX.Text = "X= " + endX.ToString();
                switchX = startX;

                startX = endX;

                endX = switchX;




            }


            if (startY < endY)
            {
                this.lblEndPixelsXY.Text += endY.ToString();
                this.lblEndY.Text = "Y= " + endY.ToString();
                this.lblStartXY.Text += startY.ToString();
                this.lblStartY.Text = "Y= " + startY.ToString();

            }
            else
            {
                this.lblEndPixelsXY.Text += startY.ToString();
                this.lblEndY.Text = "Y= " + startY.ToString();
                this.lblStartXY.Text += endY.ToString();
                this.lblStartY.Text = "Y= " + endY.ToString();
                switchY = startY;
                startY = endY;
                endY = switchY;

            }





            trigger = 0;
            // picOCRImage.Refresh();

        }

       


      

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {

                Application.Exit();
            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {

            SelectPicture();


        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            SelectPicture();
        }

        private void SelectPicture()
        {
            //***********************************
            //*****Open Button*****************
            //***********************************



            //Standard PicBox dimensions
            this.picOCRImage.Width = 690;
            this.picOCRImage.Height = 421;

            //Creates Image Variable
            Image OCRImage = null; ;

            this.picOCRImage.Enabled = true;
            this.toolStripMethod.Enabled = true;
            this.methodToolStripMenuItem.Enabled = true;



            //Open dialog box and creates Image variable
            do
            {
                this.diaBrowseImage.ShowDialog();

                FullPath = diaBrowseImage.FileName;

                try
                {
                    OCRImage = Image.FromFile(FullPath);
                }

                catch (FileNotFoundException)
                {
                    MessageBox.Show("Select an image to display?");

                }
            } while (OCRImage == null);



            //resizes image varibale OCRImage to fit Pic Box on form

            if (OCRImage != null)
            {
                ImageResize NewImgSize = new ImageResize();
                Size ImageSizeSet = new Size(this.picOCRImage.Width, this.picOCRImage.Height);

                Image ImageSize = NewImgSize.resizeImage(OCRImage, ImageSizeSet);

                ImagePaint_width = OCRImage.Width;
                ImagePaint_height = OCRImage.Height;




                Bitmap ResizedImage = new Bitmap(ImageSize);

                this.picOCRImage.Width = OCRImage.Width;
                this.picOCRImage.Height = OCRImage.Height;



                ImagePaint = ResizedImage;


                this.picOCRImage.Enabled = true;


                this.picOCRImage.Image = ResizedImage;
                this.picOCRImage.SizeMode = PictureBoxSizeMode.AutoSize;

                pbbox_width = this.picOCRImage.Width;
                pbbox_height = this.picOCRImage.Height;
            }
        }
        private void ocr()
        {
            //***********************************
            //*****Process Button*****************
            //***********************************

            //Produces an error if cmbMethod is empty
            //Converts the path of the image to filename, pathname, and fullpath if cmbMethod is not empty


            if (METHOD == "")
            {
                MessageBox.Show("Please select a barcode/language item!");
            }
            else
            {


                FullPath = diaBrowseImage.FileName;



                CmbSelection cmbValue = new CmbSelection();



                string strFileName = Path.GetFileName(FullPath);
                int size = strFileName.Length;
                string strPathName = Path.GetFullPath(FullPath);
                strPathName = strPathName.Remove(strPathName.Length - size);
                StringBuilder theOCRResults = new StringBuilder(1000);

                string strTessdataPath = System.IO.Directory.GetCurrentDirectory() + "\\tessdata\\";



                string selText = METHOD;
                int cmbvalue = cmbValue.getValue(selText);


                if (OCRGUI2008.DLLImport.LoadKernel(null, "eng") == 0)
                {
                    this.txtOCRResults.Text = "Load Kernel Failed.";
                }
                else
                {
                    //Runs OCRDLL.dll and retrieves OCR resutls

                    int u = OCRGUI2008.DLLImport.GetOcrResult(strFileName, strPathName, startX, startY, endX, endY, cmbvalue, theOCRResults, 10);


                    //if (cmbvalue == 3 || cmbvalue == 6)
                    //{
                    //    //converts OCR results to chinese using a dll
                    //    UTF8ToUnicode ChineseConversion = new UTF8ToUnicode(theOCRResults, cmbvalue);

                    //}


                    //Assigns the OCR reults to the Results Text box.

                    this.txtOCRResults.Text = Convert.ToString(theOCRResults);


                }

            }
        }






        

        private void cmbMethodFill(ToolStripComboBox meth)
        {

            //Adds the selctions to the method Cmb box
            meth.Items.Add("0.) Digits");
            meth.Items.Add("1.) Digits with Decimal");
            meth.Items.Add("2.) English");
            meth.Items.Add("3.) Subset Chinese Only");
            meth.Items.Add("4.) 1D-Barcode");
            meth.Items.Add("6.) Chinese All");
        }
        private void cmbMethodFill(ComboBox meth)
        {

            //Adds the selctions to the method Cmb box
            meth.Items.Add("0.) Digits");
            meth.Items.Add("1.) Digits with Decimal");
            meth.Items.Add("2.) English");
            meth.Items.Add("3.) Subset Chinese Only");
            meth.Items.Add("4.) 1D-Barcode");
            meth.Items.Add("6.) Chinese All");
        }

        private void cmbLanguagesFill(ToolStripComboBox cmblang)
        {
            string[] lineOfContents = File.ReadAllLines("GoogleLanguages\\GoogleLangs.txt");
            foreach (var line in lineOfContents)
            {
                string[] tokens = line.Split('\t');
                cmblang.Items.Add(tokens[0]);

            }
        }
        private void cmbLanguagesFill(ComboBox cmblang)
        {
            string[] lineOfContents = File.ReadAllLines("GoogleLanguages\\GoogleLangs.txt");
            foreach (var line in lineOfContents)
            {
                string[] tokens = line.Split('\t');
                cmblang.Items.Add(tokens[0]);

            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ocr();

        }

        private void toolStripMethodComboBoxButton_SelectedIndexChanged(object sender, EventArgs e)
        {
            METHOD = this.toolStripMethodComboBoxButton.Text;
            this.toolStripOCRButton.Enabled= true;
            this.OCRToolStripMenuItem.Enabled = true;
        }

        private void toolStripMethodComboBoxButton_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMethodComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            METHOD = this.toolStripMethodComboBox.Text;
        }

        private void txtOCRResults_TextChanged(object sender, EventArgs e)
        {
            this.toolStripLanguageButton.Enabled = true;
            this.languageToolStripMenuItem.Enabled = true;
            this.translateToolStripMenuItem.Enabled = true;
            this.toolStripTranslateButton.Enabled = true;
    
            
        }

        private void toolStripFromComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            fromLang = this.toolStripFromComboBox.Text;
        }
     
        private void toolStripToComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            toLang = this.toolStripToComboBox.Text;
        }

        private void toolStripFromComboBoxButton_SelectedIndexChanged(object sender, EventArgs e)
        {
            fromLang = this.toolStripFromComboBoxButton.Text;
        }

        private void toolStripToComboBoxButton_SelectedIndexChanged(object sender, EventArgs e)
        {
            toLang = this.toolStripToComboBoxButton.Text;
        }

        private void Translate()
        {
            if (fromLang != "" && toLang != "")
            {
                cmbLangSelect from = new cmbLangSelect();
                cmbLangSelect to = new cmbLangSelect();
                googleTranslate res = new googleTranslate();
                

                string result = res.TranslateGoogle(this.txtOCRResults.Text, from.fromtoLang(fromLang), to.fromtoLang(toLang));

                this.txtTranslate.Text = result;

            }
            else
            {
                MessageBox.Show("Please select a language to translate");

            }
        }
      
        
        
        
        //Test used to confirm internet connection
        public bool http_test()
        {
            try
            {

                string website_address;
                website_address = "http://www.google.com";

                WebRequest myWebrequest = WebRequest.Create(website_address);
                myWebrequest.Timeout = 3000;
                resp = (HttpWebResponse)myWebrequest.GetResponse();

                if (resp.StatusCode.ToString().Equals("OK"))
                {
                   // MessageBox.Show("Connection Successful.");
                    return true;
                }
                else
                {

                    MessageBox.Show("Connecting to the internet failed , please check your internet connection or the website " + website_address);
                    return false;
                }
            }
            catch (Exception exc)
            {

                MessageBox.Show("Internet connection unavailable: ");
                return false;
            }
            finally
            {
                if (resp != null) resp.Close();
            }

        }
        private void toolStripTranslateButton_Click(object sender, EventArgs e)
        {
            Translate();
        }

        private void translateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Translate();
        }

        


        private void OCRToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ocr();
        }

        private void zoomToolStripMenuItem_Click(object sender, EventArgs e)
        {

            ZoomIn();


        }



      

        private void zoomToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            ZoomOut();
        }
       
        private void ZoomIn()
        {
            ZoomMethods ZoomIn = new ZoomMethods();

            ZoomIn.ZoomIn(this.picOCRImage, this.OCRPanel);
            pbbox_width = this.picOCRImage.Width;
            pbbox_height = this.picOCRImage.Height;
        }

        private void ZoomOut()
        {

            ZoomMethods ZoomOut = new ZoomMethods();

            ZoomOut.ZoomOut(this.picOCRImage, this.OCRPanel);
            pbbox_width = this.picOCRImage.Width;
            pbbox_height = this.picOCRImage.Height;
        }
//Tool strip menu edit option to select all texts from selected textbox
        private void SelectAllText()
        {
            if (imgPathName.SelectionLength == 0 || txtOCRResults.SelectionLength == 0 || txtTranslate.SelectionLength == 0)
            imgPathName.SelectAll();
            txtOCRResults.SelectAll();
            txtTranslate.SelectAll();
           // imgPathName.Copy();

        }

//Tool strip menu edit option to copy all text from selected textbox
        private void CopyAllText()
        {


            if (imgPathName.SelectionLength > 0 || txtOCRResults.SelectionLength > 0 || txtTranslate.SelectionLength > 0)
                    imgPathName.Copy();
                    txtOCRResults.Copy();
                    txtTranslate.Copy();

        }



        private void CutImgPathName()
        {


              //if (imgPathName.SelectionLength > 0 || txtOCRResults.SelectionLength > 0 || txtTranslate.SelectionLength > 0)

              //    imgPathName.Cut();
              //    txtOCRResults.Cut();
              //    txtTranslate.Cut();
            CopyAllText();

            imgPathName.Text = "";
          }


        private void CuttxtOCRResults()
        {
            CopyAllText();


            txtOCRResults.Text = "";
        }


        private void CuttxtTranslate()
        {
            CopyAllText();


            txtTranslate.Text = "";

        }




//Tool strip menu edit option to paste imgPathName text from selected textbox
        private void PasteImgPathName()
        {
            //if (imgPathName.SelectionLength > 0)
            //{
            //    imgPathName.SelectionStart = imgPathName.SelectionStart + imgPathName.SelectionLength;
            //} 
            //imgPathName.Paste();
            this.imgPathName.Text = Clipboard.GetText();

            
          
        }


        private void PastetxtOCRREsults()
        {
            //if(txtOCRResults.SelectionLength > 0)
            //{
            //txtOCRResults.SelectionStart = txtOCRResults.SelectionStart + txtOCRResults.SelectionLength;
            //}
  
            //txtOCRResults.Paste();

            this.txtOCRResults.Text = Clipboard.GetText();
            

         }
        private void PastetxtTranslate()
        {
            //if (txtTranslate.SelectionLength > 0)
            //{
            //    txtTranslate.SelectionStart = txtTranslate.SelectionStart + txtTranslate.SelectionLength;
            //}


            //txtTranslate.Paste();
            this.txtTranslate.Text = Clipboard.GetText();
            
        }
        private void toolStripZoomInButton_Click(object sender, EventArgs e)
        {
            ZoomIn();
        }

        private void toolStripZoomOutButton_Click(object sender, EventArgs e)
        {
            ZoomOut();
        }







        private void toolStripLanguageButton_Click(object sender, EventArgs e)
        {

        }

        private void toolStripFromComboBoxButton_Click(object sender, EventArgs e)
        {

        }

       

 

        private void toolStripMethod_Click(object sender, EventArgs e)
        {

        }

        

        private void toolStripOpen_Click(object sender, EventArgs e)
        {
            SelectPicture();
            this.imgPathName.Text = FullPath;
        }

        private void buttonOcr_Click(object sender, EventArgs e)
        {
            ocr();
        }

       
        private void buttonTranslate_Click(object sender, EventArgs e)
        {
            Translate();
            http_test();
        }






        private void cmbMethod_Click(object sender, EventArgs e)
        {
        }

        private void cmbMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            METHOD = this.cmbMethod.Text;
        }

        
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            SelectPicture();
            this.imgPathName.Text = FullPath;

        }

        private void cmbLanTo_SelectedIndexChanged(object sender, EventArgs e)
        {

            toLang = this.cmbLanTo.Text;


        }

        private void cmbLanFrom_SelectedIndexChanged(object sender, EventArgs e)
        {
            fromLang = this.cmbLanFrom.Text;

        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectAllText();
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CopyAllText();
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            

        if (this.imgPathName.Focus())
            {
                PasteImgPathName();
            }

        else if (this.txtOCRResults.Focus())
            {
                PastetxtOCRREsults();
                
            }
           
            else if (this.txtTranslate.Focus())
            
           {
                PastetxtTranslate();
            }

        }

        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
           if (this.imgPathName.Focus())
            {
                CutImgPathName();
            }
            else  if (this.txtOCRResults.Focus())
            {
                CuttxtOCRResults();

            }
            

            else if (this.txtTranslate.Focus())
            {
                CuttxtTranslate();
            }
        }

        private void frmOCR_FormClosing(object sender, FormClosingEventArgs e)
        {







            //Resolution.CResolution ChangeRes = new Resolution.CResolution(RES1, RES2);
           
        }

        

        //public void paste_selection(Object sender, EventArgs e, Control _winControl)
        //{
        //     if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
        //     {
               

        //     }


        //}
       
        }


        
       

     }
            
        
        
 
   

